<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <script>
        // 用递归求n的阶层
        function plus(n) 
        {
            if(n===1)
            {
                return 1;
            }
            return plus(n-1)*n
        }
       var re= plus(4)
       console.log(re);


       var data=[
           {
               id:1,
               name:'广东',
               city:[
                   {
                       id:2,
                       name:'广州',
                       city:[
                           {id:3,name:'白云区'},
                           {id:4,name:'天河区'},
                           {id:5,name:'海珠区'}
                       ]
                   }
               ]
           },
           {
               id:10,
               name:'广西',
               city:[
                   {
                       id:11,
                       name:'南宁',
                       city:[
                           {id:12,name:'青秀区'},
                           {id:13,name:'西乡塘区'},
                           {id:14,name:'江南区'}
                       ]
                   }
               ]
           },
       ]

       function getCityById(id,data)
       {
           cityName=''
           for(var i in data)
           {
               if(data[i].id==id)
               {
                cityName=data[i].name
                return cityName
               }
               if(data[i].city&&data[i].city.length>0)
                {
                    cityName=getCityById(id,data[i].city)
                    if(cityName)  //表示data[i].city存在 就return
                    {
                        return cityName
                    }
                }
           }
           return cityName
           
       }
       console.log(getCityById(14,data));
    </script>
    
</body>
</html>